package com.tjetc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * @author zc
 * @Date 2025/7/8 下午2:25
 */
@Configuration
public class MessagingConfig {
    //spring高版本需要信任一些内容
    @Bean
    public SimpleMessageConverter converter() {
        SimpleMessageConverter converter = new SimpleMessageConverter();
        // 示例： com. foo.* 、 *.MyClass
        converter.setAllowedListPatterns(Arrays.asList("*"));
        return converter;
    }
    //定义消息队列和绑定交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topicExchange");
    }

    @Bean
    public Queue BClassifyQueue(){
        return new Queue("bClassifyQueue");
    }

   /* @Bean
    Binding BindTopicA(Queue topicA, TopicExchange topicExchange){
        return BindingBuilder.bind(topicA).to(topicExchange).with("topic.bClassify");
    }*/

    @Bean
    public Queue userQueue(){
        return new Queue("userQueue");
    }

    @Bean
    Binding BindTopicB(Queue userQueue, TopicExchange topicExchange){
        return BindingBuilder.bind(userQueue).to(topicExchange).with("topic.user");
    }
}
